const mqtt = require('mqtt')

let deviceCode = "E6A2617A65CF"

let username = "admin"
let password = "nttieren0513"

// iot生产环境
let connectUrl = 'wss://iot.ironmanapi.com:8084/mqtt'
// connectUrl = 'ws://iot.ironmanapi.com:8083/mqtt'
// iot测试环境
// connectUrl = 'wss://test.ironmanapi.com:8084/mqtt'
connectUrl = 'ws://test.ironmanapi.com:8083/mqtt'
// iot单体
// connectUrl = 'ws://172.16.8.31:8083/mqtt'
// 空军医院
// connectUrl = 'ws://101.43.155.8:8083/mqtt'

// 仪表apk定制开发商标识
const apkSupporterCode = "iot001"
const clientId = `${apkSupporterCode}_${deviceCode}`

// 连接选项
const options = {
    clean: true, // true: 清除会话, false: 保留会话
    connectTimeout: 15000, // 超时时间
    clientId,
    username,
    password,
    keepalive: 5,
    will: {
        topic: `will-msg/${clientId}`,
        payload: 'offline',
        qos: 2,
        retain: false
    }
}

const client = mqtt.connect(connectUrl, options)

module.exports = {
    client,
    apkSupporterCode,
    deviceCode
}
